<?php

/**
 * Class device_config
 *
 * 设备配置
 */
class device_config
{
    public static $STATUS = array(
        0 => '未激活',
        1 => '停用',
        2 => '已绑定',
        3 => '损坏',
        4 => '已发货',
        5 => '入库',
        6 => '生产完成',
    );

    /**
     * @var array
     *
     * prefix     编号前缀
     * id         类型唯一识别, res_name (即将废弃)
     * class      设备类型, 用于自动生成算法
     * name       设备名称
     * bindable   绑定
     * table      表名称 (即将废弃)
     */
    /*
INSERT INTO device(type,code,add_time,status,old_id) SELECT  substring(machine.machine_no,1,2) as tyepe,machine.machine_no,NOW(),machine.status,machine.id FROM machine;
INSERT INTO device(type,code,add_time,status,old_id) SELECT  substring(adbox.adbox_no,1,2) as tyepe,adbox.adbox_no,NOW(),adbox.status,adbox.id FROM adbox;
INSERT INTO device(type,code,add_time,status,old_id) SELECT  substring(game_table.game_table_no,1,2) as tyepe,game_table.game_table_no,NOW(),game_table.status,game_table.id FROM game_table;
INSERT INTO device(type,code,add_time,status,old_id) SELECT  substring(ibeacon.ibeacon_no,1,2) as tyepe,ibeacon.ibeacon_no,NOW(),ibeacon.status,ibeacon.id FROM ibeacon;
     *
     * 线上运行
UPDATE `store_device_record` as s, `device` as d SET s.type='MX', s.dev_id = d.id WHERE s.res_name = 'machine' AND s.res_id = d.old_id;
UPDATE `store_device_record` as s, `device` as d SET s.type='ZX', s.dev_id = d.id WHERE s.res_name = 'old_machine' AND s.res_id = d.old_id;
UPDATE `store_device_record` as s, `device` as d SET s.type='FX', s.dev_id = d.id WHERE s.res_name = 'warmer_IV' AND s.res_id = d.old_id;
UPDATE `store_device_record` as s, `device` as d SET s.type='AD', s.dev_id = d.id WHERE s.res_name = 'adbox' AND s.res_id = d.old_id;
UPDATE `store_device_record` as s, `device` as d SET s.type='TA', s.dev_id = d.id WHERE s.res_name = 'game_table' AND s.res_id = d.old_id;
UPDATE `store_device_record` as s, `device` as d SET s.type='OS', s.dev_id = d.id WHERE s.res_name = 'ibeacon' AND s.res_id = d.old_id;
UPDATE `store_device_record` as s, `device` as d SET s.type='CS', s.dev_id = d.id WHERE s.res_name = 'TMS' AND s.res_id = d.old_id;
     *
UPDATE `store_device_relation` as sd, `store_device_record` as sr SET sd.type = sr.type, sd.dev_id = sr.dev_id WHERE sd.res_name = sr.res_name AND sd.res_id = sr.res_id
     */
    public static $TYPES = array(
        'ZX' => array(
            'prefix' => 'ZX',
            'id' => 'old_machine',
            'class' => 'METAL_BOX',
            'name' => '二代保温箱',
            'bindable' => 1,
        ),
        'MX' => array(
            'prefix' => 'MX',
            'id' => 'machine',
            'class' => 'WARMER_BOX',
            'name' => '三代保温箱',
            'bindable' => 1,
        ),
        'FX' => array(
            'prefix' => 'FX',
            'id' => 'warmer_IV',
            'class' => 'WARMER_BOX',
            'name' => '四代保温箱',
            'bindable' => 1,
        ),
        'AD' => array(
            'prefix' => 'AD',
            'id' => 'adbox',
            'class' => 'AD_BOX',
            'name' => '广告机',
            'bindable' => 1,
        ),
        'TA' => array(
            'prefix' => 'TA',
            'id' => 'game_table',
            'class' => 'AD_BOX',
            'name' => '游戏桌',
            'bindable' => 1,
        ),
        'OS' => array(
            'prefix' => 'OS',
            'id' => 'ibeacon',
            'class' => 'IBEACON',
            'name' => '外置摇一摇设备',
            'bindable' => 1,
        ),
        'CS' => array(
            'prefix' => 'CS',
            'id' => 'TMS',
            'class' => 'IBEACON',
            'name' => '影院摇一摇设备',
            'bindable' => 1,
        ),
    );

    /**
     * @var array
     *
     * 编号生成过算法配置
     */
    public static $RULES = array(
        'METAL_BOX' => array(
            'RESERVED' => array(
                '厂商',
                1,
                array(
                    '4' => '新供应商',
                )
            ),
            'RAND' => 8,
        ),
        'WARMER_BOX' => array(
            'BATCH' => array(
                '批次',
                1,
                array(
                    '1' => '无屏工程机',
                    '2' => '无屏样机',
                    '3' => '无屏量产机',
                    '4' => '无屏次品',
                    '5' => '无屏翻新机',
                    '6' => '有屏工程机',
                    '7' => '有屏样机',
                    '8' => '有屏量产机',
                    '9' => '有屏次品',
                    '0' => '有屏翻新机',
                )
            ),
            'COLOR' => array(
                '颜色',
                1,
                array(
                    '1' => '有Ibeacon紫',
                    '2' => '有Ibeacon白',
                    '3' => '以后再定',
                    '4' => '以后再定',
                    '5' => '以后再定',
                    '6' => '无Ibeacon紫',
                    '7' => '无Ibeacon白',
                )
            ),
            'RAND' => 8,
        ),
        'AD_BOX' => array(
            'SIZE' => array(
                '规格',
                3,
                array(
                    '430' => '430尺寸',
                    '180' => '180尺寸'
                )
            ),
            'BATCH' => array(
                '批次',
                1,
                array(
                    '1' => '工程机',
                    '2' => '样机',
                    '3' => '量产机',
                    '4' => '次品',
                    '5' => '翻新机',
                )
            ),
            'RAND' => 6,
        ),
        'IBEACON' => array(
            'STYLE' => array(
                '样式',
                2,
                array(
                    '13' => '黑盒型i3',
                    '27' => '工卡型'
                )
            ),
            'BATCH' => array(
                '批次',
                1,
                array(
                    '1' => '工程机',
                    '2' => '样机',
                    '3' => '量产机',
                    '4' => '次品',
                    '5' => '员工机',
                )
            ),
            'RAND' => 6,
        ),
    );

    public static function res_index() {
        return self::id_index();
    }

    public static function id_index() {
        return api_helper::array_to_filelds_assoc('id', self::$TYPES);
    }

    public static function prefix_index() {
        return self::$TYPES;
    }

    public static function name_index() {
        return api_helper::array_to_filelds_assoc('name', self::$TYPES);
    }

    public static function create_config() {
        $c = self::$SOURCE;
        foreach ($c as & $item) {
            $item['rule'] = self::$CREATER[$item['class']];
        }
        return $c;
    }
}
